package sys.spvisor.console.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import sys.spvisor.core.entity.people.PeopleShowInfo;
import sys.spvisor.core.entity.people.TEvectionStatus;
import sys.spvisor.core.entity.people.TPeople;
import sys.spvisor.core.entity.people.TPeopleAndUerRole;
import sys.spvisor.core.entity.people.TPeoplePoststatus;
import sys.spvisor.core.service.people.PeopleService;


@Controller
@RequestMapping("/people")
public class PeopleController {

	
	@Autowired
	PeopleService peopleService;
	
	
	@ResponseBody
	@RequestMapping("/getPostStatus.ajax")
	public List<TPeoplePoststatus> getPostStatus() {
//		System.out.println("______________________________________________________");
//		System.out.println(peopleService.getPostStatus());
		return peopleService.getPostStatus();
	}
	
	@ResponseBody
	@RequestMapping("/getHolidayTravelStatus.ajax")
	public List<TEvectionStatus> getHolidayTravelStatus() {
		/*System.out.println("______________________________________________________");
		System.out.println(peopleService.getHolidayTravelStatus());*/
		return peopleService.getHolidayTravelStatus();
	}
	
	@ResponseBody
	@RequestMapping("/getAllPeople.ajax")
	public List<PeopleShowInfo> getAllPeople() {
		System.out.println("______________________________________________________");
		System.out.println(peopleService.getAllPeople());
		return peopleService.getAllPeople();
	}

	
	@ResponseBody
	@RequestMapping("/getAllPeopleUser.ajax")
	public List<TPeopleAndUerRole> getAllPeopleUser() {
		System.out.println("______________________________________________________");
		System.out.println(peopleService.getAllPeopleUser());
		return peopleService.getAllPeopleUser();
	}

	
    @RequestMapping("/queryPeople.ajax")    
	public @ResponseBody Map<String, Object> queryPeople(TPeople msg) {
		Map<String, Object> result = new HashMap<String, Object>(3);
		System.out.println("进入查询ajax");
		List<TPeople> lists = null;
		try {
			lists = peopleService.selectByExample(msg);
			int count = lists.size();
			result.put("total", count);
			result.put("rows", lists);
			result.put("success", true);
			result.put("message", "查询成功");
		} catch (Exception e) {
			result.put("rows", null);
			result.put("success", false);
			result.put("message", "没有查到相关项目，请重新输入");
		}
		System.out.println("返回结果"+result);
		return result;
		
	}
    
    @RequestMapping("/AddPeopleData.ajax")    
   	public @ResponseBody Map<String, Object> AddPeopleData(TPeople people) {
   		Map<String, Object> result = new HashMap<String, Object>(2);
   		System.out.println("进入查询ajax");   		
   		try {
   			peopleService.addPeopleData(people);
			result.put("success", true);
			result.put("message", "新增人员成功！");
		} catch (Exception e) {
			result.put("success", false);
			result.put("message", "新增人员失败！");
		}
   		System.out.println("返回结果"+result);
   		return result;
   		
   	}
    
    @RequestMapping("/EditPeopleData.ajax")    
   	public @ResponseBody Map<String, Object> EditPeopleData(TPeople people) {
   		Map<String, Object> result = new HashMap<String, Object>(2);
   		try {
   			peopleService.EditPeopleData(people);
			result.put("success", true);
			result.put("message", "修改人员成功！");
		} catch (Exception e) {
			result.put("success", false);
			result.put("message", "修改人员失败！");
		}
   		System.out.println("返回结果"+result);
   		return result;
   		
   	}
    
	@RequestMapping(value="/RemovePeopleData.ajax", method = { RequestMethod.POST })
	public  @ResponseBody Map<String, Object> RemovePeopleData(@RequestParam("peoId") String peoId) {
		Map<String, Object> result = new HashMap<String, Object>(2);
   		try {
   			peopleService.RemovePeopleData(peoId);
			result.put("success", true);
			result.put("message", "删除人员成功！");
		} catch (Exception e) {
			result.put("success", false);
			result.put("message", "删除人员失败！");
		}
   		System.out.println("返回结果"+result);
   		return result;
		
	}
	
}
